package Week2.J0423;


// 动态规划??? √
// 思路: 因为只能向右或向左走
// 所以每次要走的时候, 检测arr[i]整行和整列的大小，谁大走谁 总和相等走当前最大

// 反推 + 动态规划 ( + 递归 ? )
// 无需反推和递归, 简单题想复杂了😂

import java.util.Scanner;

public class 字母收集 {
    static int sum = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] arr = new int[n+1][m+1];
        for (int i = 1; i <= n; i++) {
            String ch = scanner.next();
            for (int j = 1; j <= m; j++) {
                int tmp;
                if (ch.charAt(j-1) == 'l') {
                    tmp = 4;
                }else if (ch.charAt(j-1) == 'o') {
                    tmp = 3;
                }else if (ch.charAt(j-1) == 'v') {
                    tmp = 2;
                }else if (ch.charAt(j-1) == 'e') {
                    tmp = 1;
                }else {
                    tmp = 0;
                }
                arr[i][j] = tmp;
            }
        }

        // 开始走
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                arr[i][j] += Math.max(arr[i-1][j], arr[i][j-1]);
            }
        }

        System.out.println(arr[n][m]);
    }
}
